package editorview.views;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.ui.IWorkbenchPage;

public class EditorsViewContentProvider implements ITreeContentProvider {

	private TreeViewer viewer;

	public EditorsViewContentProvider(TreeViewer viewer) {
		this.viewer = viewer;
	}

	@Override
	public void dispose() {
	}

	@Override
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
		System.out.println("*** Input changed: " + viewer + " old: " + oldInput
				+ " new: " + newInput);
	}

  @Override
  public Object[] getElements(Object inputElement) {
    if (inputElement instanceof IWorkbenchPage) {
      IWorkbenchPage page = (IWorkbenchPage) inputElement;
      return page.getEditorReferences();
    }
    return null;
  }

  @Override
  public Object[] getChildren(Object parentElement) {
    return null;
  }

	@Override
	public Object getParent(Object element) {
		// TODO Auto-generated method stub
		return null;
	}

  @Override
  public boolean hasChildren(Object element) {
    return false;
  }

  //	@Override
  //	public void updateElement(Object parent, int index) {
  //    if (parent instanceof IWorkbenchPage) {
  //      IEditorReference[] editorReferences = ((IWorkbenchPage) parent).getEditorReferences();
  //      if (editorReferences.length > index) {
  //        //        viewer.replace(parent, index, editorReferences[index]);
  //        viewer.add(parent, editorReferences[index]);
  //      } else {
  //      }
  //    }
  //	}
  //
  //	@Override
  //	public void updateChildCount(Object element, int currentChildCount) {
  //		if (element instanceof IWorkbenchPage) {
  //			int editorsCount = ((IWorkbenchPage) element).getEditorReferences().length;
  //			if (editorsCount != currentChildCount) {
  //				viewer.setChildCount(element, editorsCount);
  //			}
  //		}
  //	}

  //	@Override
  //	public boolean hasChildren(Object element) {
  //		return false;
  //	}

}
